import block
from block import Block, Restriction, Slot

import agent
from agent import Agent

import world
from world import BlockStack, World

import const

import channel
from channel import Channel

import threading

block1 = block.createBlock(1, 'red', 3, 2, 2);
block2 = block.createBlock(2, 'white', 8, 9, 4);
block3 = block.createBlock(3, 'green', 6, 3, 1);
block4 = block.createBlock(4, 'purple', 1, 5, 5);
block5 = block.createBlock(5, 'blue', 5, 4, 2);
block6 = block.createBlock(6, 'coral', 10, 8, 1);

stack1 = BlockStack(0, [block2])
stack2 = BlockStack(8, [block1, block3, block4])
stack3 = BlockStack(12, [block5, block6])

world = World([stack1, stack2, stack3])
world.getBlocks()

rgreen = Restriction(const.COLOR, 'green', const.EQ)
rheavy = Restriction(const.WEIGHT, 4, const.GT)
rsmall = Restriction(const.WIDTH, 3, const.LE)
rwide = Restriction(const.WIDTH, 8, const.GE)
rcoral = Restriction(const.COLOR, 'coral', const.EQ)

slot1 = Slot(const.NORMAL, [rgreen, rheavy])
slot2 = Slot(const.NORMAL, [])
slot3 = Slot(const.NORMAL, [rsmall])
slot4 = Slot(const.NORMAL, [rwide])
slot5 = Slot(const.NORMAL, [rcoral])

agent0 = Agent("agent0", world, [[slot2, slot2]])
agent1 = Agent("agent1", world, [[slot1], [slot5]])
agent2 = Agent("agent2", world, [[slot4, slot3]])

channel = Channel([agent0, agent1, agent2])

agent0.setChannel(channel)
agent1.setChannel(channel)
agent2.setChannel(channel)

class RunAgent(threading.Thread):
	def __init__(self, agent):
		threading.Thread.__init__(self)
		self.agent = agent

	def run(self):
		self.agent.chooseBlocks()

RunAgent(agent0).start()
RunAgent(agent1).start()
RunAgent(agent2).start()

# world.putOnBlock(4,2)
# world.putOnGround(6)
# world.putOnBlock(3,6)
# world.putOnBlock(1,4)
# world.putOnBlock(3,1)
# world.putOnBlock(3,6)
# world.putOnBlock(1,5)
